package com.jwdf.uda.view.dialog;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.view.LayoutInflater;
import android.view.View;

import com.jwdf.uda.R;
import com.jwdf.uda.databinding.DialogSystemAlertBinding;
import com.jwdf.uda.utils.StringUtils;

/**
 * Created by Administrator on 2017/1/12.
 */

public class SysMsgAlertDialog extends BaseDialog {
    private DialogSystemAlertBinding mDataBinding;
    private boolean mCancelable = true;
    private String mContent;
    private SysMsgAlertDialog.CallbackListener mListener;

    public interface CallbackListener {
        void onClose();
    }

    public SysMsgAlertDialog(Context context, String content) {
        this(context, content, null);
    }

    public SysMsgAlertDialog(Context context, String content, SysMsgAlertDialog.CallbackListener listener) {
        super(context);
        setCancelable(false);
        this.mContent = content;
        this.mListener = listener;
    }

    public void setCallbackListener(SysMsgAlertDialog.CallbackListener listener) {
        this.mListener = listener;
    }

    public void setCanBackDismiss(boolean canBackDismiss) {
        this.mCancelable = canBackDismiss;
    }

    @Override
    protected View onInflateView(LayoutInflater inflater) {
        mDataBinding = DataBindingUtil.inflate(inflater, R.layout.dialog_system_alert, null, false);
        return mDataBinding.getRoot();
    }

    @Override
    protected void onInitView(View view) {
        mDataBinding.content.setText(StringUtils.filterNullAndTrim(mContent));
        mDataBinding.flClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (mListener != null) mListener.onClose();
            }
        });
    }

    @Override
    public void onBackPressed() {
        if (mCancelable) {
            super.onBackPressed();
        }
    }
}
